//
//  DiscoveryActicleListViewController.m
//  PigMarket
//
//  Created by 张敬 on 2019/9/2.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "DiscoveryActicleListViewController.h"
#import "DiscoveryWebViewController.h"
#import "DiscoveryActicleViewController.h"
#import "FoundActicleTypeModel.h"
#import "XXPageTabView.h"

#import "DiscoverySearchViewController.h"


@interface DiscoveryActicleListViewController ()<XXPageTabViewDelegate>

@property (nonatomic , strong) XXPageTabView *pageTabView;
@property (nonatomic, strong) NSArray *childTitles;


@end

@implementation DiscoveryActicleListViewController

- (void)viewDidLoad{
    
    [super viewDidLoad];
    [self setupUI];
    //[self initData];
}


#pragma mark - init method

- (void)setupUI {
    
    self.view.backgroundColor = KWhiteColor;
    
    {
        self.baseNavView.navTitleLabel.text = @"清饲·生活";
        self.baseNavView.line.hidden = YES;
    }
    
    {
        [self.baseNavView.rightNavBtn setImage:[UIImage imageNamed:@"meat_buy_search"] forState:UIControlStateNormal];
        self.baseNavView.rightNavBtn.hidden = NO;
        self.baseNavView.rightNavBtn.isNeedAnimation = YES;
        
        @weakify(self);
        self.baseNavView.rightNavBtn.tapBlock = ^{
            @strongify(self);
                    
            DiscoverySearchViewController *vc= [[DiscoverySearchViewController alloc] init];
            vc.titles = self.titles;
            [self presentViewController:vc animated:YES completion:nil];
        };
    }
}


- (void)setupLayout{
    
    [self.pageTabView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(TJ_NavBarHeight);
    }];
}


//- (void)initData {
//    
//    FoundActicleListParam *param = [[FoundActicleListParam alloc] init];
//    param.page = @1;
//    param.limit = @10;
//    param.memberId = kMemberId;
//    param.qsArticleId = @1;
//    param.articleType = @0;
//    
//    @weakify(self);
//    [[[MeatFoundApi sharedInstance] getArticleDetailListByParams:param] subscribeNext:^(FoundActicleListModel * _Nullable x) {
//        @strongify(self);
//        
//        
//    }error:^(NSError * _Nullable error) {
//        
//    }];
//}


#pragma mark - delegate
- (void)scrollToLast:(id)sender {
    [self.pageTabView setSelectedTabIndexWithAnimation:self.pageTabView.selectedTabIndex-1];
}

- (void)scrollToNext:(id)sender {
    [self.pageTabView setSelectedTabIndexWithAnimation:self.pageTabView.selectedTabIndex+1];
}

- (void)pageTabViewDidEndChange{
    
}


#pragma mark - target action

- (void)transferManagerTapped {
    
}

#pragma mark - setter methods
- (void)setTitles:(NSArray *)titles{
    
    _titles = titles;
    
    NSMutableArray *aims = [NSMutableArray array];
    [titles enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        FoundActicleTypeItem *item = (FoundActicleTypeItem *)obj;
        [aims addObject:item.text];
        
        DiscoveryActicleViewController *vc = [[DiscoveryActicleViewController alloc] init];
        vc.type = item.value;
        [self addChildViewController:vc];
        
    }];
    
    self.childTitles = [aims copy];
    [self.view addSubview:self.pageTabView];
    [self setupLayout];

}

#pragma mark - getter methods

- (XXPageTabView *)pageTabView {
    if (!_pageTabView) {
        _pageTabView = [[XXPageTabView alloc] initWithChildControllers:self.childViewControllers childTitles:self.childTitles];
        _pageTabView.delegate = self;
        _pageTabView.indicatorStyle = XXPageTabIndicatorStyleFollowText;//跟随文本变化长度
        _pageTabView.titleStyle = XXPageTabTitleStyleBlend;//渐变
        _pageTabView.selectedTabIndex = 0;
        _pageTabView.separatorColor = mBackgroudColor;
        _pageTabView.tabItemFont = mFont(15);
        _pageTabView.indicatorHeight = 1;
        _pageTabView.bodyBounces = NO;
        _pageTabView.selectedColor = [UIColor colorWithHexString:@"#53C203"];
        _pageTabView.unSelectedColor = [UIColor colorWithHexString:@"#666666"];
        _pageTabView.tabBackgroundColor = [UIColor clearColor];
        _pageTabView.bodyBackgroundColor = [UIColor clearColor];
    }
    return _pageTabView;
}


@end
